home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / jockey / handlers / broadcom_wl.py < prev    next >
Encoding:
Python Source  |  2009-04-07  |  2.9 KB  |  81 lines

  1. # (c) 2008 Canonical Ltd.
  2. # Author: Martin Pitt <martin.pitt@ubuntu.com>
  3. # License: GPL v2 or later
  4.  
  5. import re, os.path, logging, subprocess
  6. from glob import glob
  7.  
  8. from jockey.oslib import OSLib
  9. from jockey.handlers import KernelModuleHandler
  10.  
  11. # dummy stub for xgettext
  12. def _(x): return x
  13.  
  14. class BroadcomWLHandler(KernelModuleHandler):
  15.     '''Handler for Broadcom Wifi chipsets which use the wl module.'''
  16.  
  17.     def __init__(self, ui):
  18.         self.bl_file = os.path.join(os.path.dirname(
  19.             OSLib.inst.module_blacklist_file), 'blacklist-bcm43.conf')
  20.         self._free = False
  21.         KernelModuleHandler.__init__(self, ui, 'wl',
  22.             name=_('Broadcom STA wireless driver'))
  23.  
  24.     def enabled(self):
  25.         km =  KernelModuleHandler.enabled(self)
  26.         bcm = OSLib.inst.module_blacklisted('bcm43xx')
  27.         b43 = OSLib.inst.module_blacklisted('b43')
  28.         b43_legacy = OSLib.inst.module_blacklisted('b43legacy')
  29.         b43_loaded = KernelModuleHandler.module_loaded('b43xx') or \
  30.                      KernelModuleHandler.module_loaded('b43')   or \
  31.                      KernelModuleHandler.module_loaded('b43legacy')
  32.         logging.debug('BroadcomWLHandler enabled(): kmod %s, bcm43xx: %s, b43: %s, b43legacy: %s' % (
  33.             km and 'enabled' or 'disabled',
  34.             bcm and 'blacklisted' or 'enabled',
  35.             b43 and 'blacklisted' or 'enabled',
  36.             b43_legacy and 'blacklisted' or 'enabled'))
  37.  
  38.         return (km and not b43_loaded) or (km and bcm and b43 and b43_legacy)
  39.  
  40.     def used(self):
  41.         '''Return if the handler is currently in use.'''
  42.  
  43.         return KernelModuleHandler.used(self) and self.enabled() and \
  44.             not (KernelModuleHandler.module_loaded('b43') or
  45.             KernelModuleHandler.module_loaded('b43legacy') or
  46.             KernelModuleHandler.module_loaded('bcm43xx'))
  47.  
  48.     def enable(self):
  49.         '''Disable b43 drivers, so that wl can become active.
  50.         
  51.         This also adds a workaround for loading wl first if b44 is used.
  52.         '''
  53.         if not os.path.exists(self.bl_file):
  54.             f = open(self.bl_file, 'w')
  55.             f.write('''blacklist bcm43xx
  56. blacklist b43
  57. blacklist b43legacy
  58. blacklist ssb
  59. ''')
  60.             if KernelModuleHandler.module_loaded('b44'):
  61.                 f.write('''# load wl before b44 so that both work
  62. blacklist b44
  63. install wl modprobe -r b43 b44 b43legacy ssb; modprobe --ignore-install wl $CMDLINE_OPTS; modprobe --ignore-install b44
  64. ''')
  65.  
  66.             f.close()
  67.             OSLib.inst._load_module_blacklist()
  68.             subprocess.call(['/usr/sbin/update-initramfs', '-u'])
  69.  
  70.         KernelModuleHandler.enable(self)
  71.  
  72.     def disable(self):
  73.         '''Unblacklist b43 drivers again, so that they trump wl.'''
  74.  
  75.         if os.path.exists(self.bl_file):
  76.             os.unlink(self.bl_file)
  77.             OSLib.inst._load_module_blacklist()
  78.             subprocess.call(['/usr/sbin/update-initramfs', '-u'])
  79.  
  80.         KernelModuleHandler.disable(self)
  81.